package com.aiti.lulian.controller.crad;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardVersionUpdatesDto;
import com.aiti.lulian.entity.CardVersionUpdates;
import com.aiti.lulian.service.ICardVersionUpdatesService;
import com.aiti.lulian.vo.CardVersionUpdatesVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(tags = "名片版本更新说明")
@RequestMapping("/card/version/updates")
public class CardVersionUpdatesController extends WebController<CardVersionUpdates> {

    private final ICardVersionUpdatesService cardVersionUpdatesService;

    @ApiOperation("发布版本更新说明")
    @PostMapping
    public Message releaseCardVersionUpdates(@RequestBody CardVersionUpdatesDto dto) {
        dto.setUserId(findUserId());
        return cardVersionUpdatesService.releaseCardVersionUpdates(dto);
    }

    @ApiOperation("查看版本更新说明列表")
    @GetMapping("/list")
    public Message getCardVersionUpdatesList(CardVersionUpdatesDto dto) {
        Integer pageNum = dto.getPageNum();
        Integer pageSize = dto.getPageSize();
        Page<CardVersionUpdates> page = startPage(pageNum, pageSize);
        List<CardVersionUpdatesVo> list = cardVersionUpdatesService.getCardVersionUpdatesList(dto, page);
        return Success(getPageResult(list, pageNum, pageSize, page.getTotal()));
    }

    @ApiOperation("查看版本更新说明详情")
    @GetMapping("/{baseId}")
    public Message getCardVersionUpdatesDetail(@PathVariable("baseId") String baseId) {
        return Success(cardVersionUpdatesService.getCardVersionUpdatesDetail(baseId));
    }

    @ApiOperation("查看最新版本更新说明")
    @GetMapping("/latest")
    public Message getCardVersionUpdatesLatest() {
        return Success(cardVersionUpdatesService.getCardVersionUpdatesLatest());
    }

    @ApiOperation("删除版本更新说明（支持批量）")
    @DeleteMapping
    public Message deleteCardVersionUpdatesBatch(CardVersionUpdatesDto dto) {
        cardVersionUpdatesService.deleteCardVersionUpdatesBatch(dto);
        return Success();
    }
}